# conding = utf-8
import os

import yaml
from selenium.common import TimeoutException
from selenium.webdriver import ActionChains, Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from pages.page import Page
from pages.gzy.retail.outbound import left_menu_sys, left_menu, invoicesid, invoicesid_expected, find_btn, find_btn1, helpups, \
    btn_unfold, good_send, time_star, time_end, time_text, member_card, depotname, operatortext, invoicesstatus, \
    settleduser, remarkstext, insert_btn, insert_member, pickgood, close_tips_btn, insert_good_table, insert_qr_btn, \
    insert_bc_btn, insert_crh_btn, insert_good_table1, pickgood1, insert_qr_btn1, ck_btn, qx_ck_btn, view_title, bj_btn, \
    bj_input, bj_quantity, bj_dy, get_table_bh, fz_btn, sc_btn, plcz_btn, pl_delete, pl_audit, pl_anti_audit, \
    table_check, table_check1, insert_good_find, quantity_tips, cancel, insert_quantity, get_bh, tishi_text, \
    insert_quantity1, invoicesid_expected1
import time

#零售管理：零售出库
class OutboundPage(Page):


    # 查询
    def helpups_close(self):
        try:
            # 等待元素出现,超时跳过
            WebDriverWait(self.driver,1).until(
                EC.presence_of_element_located((By.XPATH, "//div[6]/div/div[1]/a"))
            )
            ele=self.driver.find_element(*helpups)
            # 执行点击操作关闭该元素
            ele.click()
        except TimeoutException:
            # 如果超时,直接跳过
            pass

    def open_outbound(self):
        #打开零售ui，如果已经打开则不会执行单击动作
        if self.display(left_menu) is False:  # 如果是隐藏状态则单击
            self.click(left_menu_sys)
        self.click(left_menu)

    def meber(self):
        #会员卡号动作链
        self.click(member_card)
        actions=ActionChains(self.driver)
        actions.send_keys(Keys.DOWN)
        actions.send_keys(Keys.ENTER)
        actions.perform()

    def depot(self):
        #仓库名称动作链
        self.click(depotname)
        actions=ActionChains(self.driver)
        actions.send_keys(Keys.ENTER)
        actions.perform()

    def operator(self):
        #操作员动作链
        self.click(operatortext)
        actions=ActionChains(self.driver)
        actions.send_keys(Keys.ENTER)
        actions.perform()

    def settled(self):
        #结算账户动作链
        self.click(settleduser)
        actions=ActionChains(self.driver)
        actions.send_keys(Keys.DOWN)
        actions.send_keys(Keys.ENTER)
        actions.perform()

    def invoices(self):
        #单据状态动作链
        self.click(invoicesstatus)
        actions=ActionChains(self.driver)
        actions.send_keys(Keys.ENTER)
        actions.perform()

    def ingood(self):
        actions=ActionChains(self.driver)
        actions.move_to_element(insert_good_table1).click()
        actions.perform()

    def btn_unfold(self):
        # 展开隐藏的文本框
        self.click(btn_unfold)

    def actions_star(self):
        self.meber()
        self.depot()
        self.operator()
        self.settled()
        self.invoices()

    def search_input(self,invoicesidv,goodinfov,remarks):
        self.send_keys(invoicesid,invoicesidv)
        time.sleep(1)
        self.send_keys(good_send,goodinfov)
        time.sleep(1)
        self.click(time_text)
        self.click(time_star)
        time.sleep(1)
        self.click(time_end)
        self.send_keys(remarkstext,remarks)
        time.sleep(1)

    def search_btn(self):
        # 单击查找按钮
        self.click(find_btn)

    def search_result_text(self):
        #单击查找后，获取查找结果
        return self.text(invoicesid_expected)

    def search_result_text1(self):
        #单击查找后，获取查找结果
        return self.text(invoicesid_expected1)

    def search_reset(self):
        #重置查询
        self.click(find_btn1)

    def xzmember(self):
        # 新增会员卡号动作链
        self.click(insert_member)
        actions = ActionChains(self.driver)
        actions.send_keys(Keys.ENTER)
        actions.perform()

    def find_insert_btn(self):
        #单击新增
        self.click(insert_btn)

    #新增选择商品按钮
    def insert_pickgood(self):
        self.click(pickgood)

    def insert_good_serach(self):
        self.send_keys(insert_good_find)

    #新增选择数据
    def insert_table(self):
        self.click(insert_good_table)

    #新增插入行按钮
    def insert_crh_btn(self):
        self.click(insert_crh_btn)

    #插入行选择按钮
    def crh_pickgood(self):
        self.click(pickgood1)

    #插入行选择数据
    def crh_picktable(self):
        self.click(insert_good_table1)

    # 确认按钮
    def qr_btn(self):
        self.click(insert_qr_btn)
    # 确认按钮
    def crh_qr_btn(self):
        self.click(insert_qr_btn1)

    #保存按钮
    def bc_btn(self):
        self.click(insert_bc_btn)

    #查看按钮
    def ck_btn(self):
        self.click(ck_btn)
    #退出详情界面
    def tc_ck_btn(self):
        self.click(qx_ck_btn)
    #获取弹窗标题
    def view(self):
        return self.find_element(view_title).text

    #单击编辑按钮
    def update_btn(self):
        self.click(bj_btn)
    #编辑数量
    def update_quantity(self,value):
        self.send_keys(bj_quantity,value)

    def update_dy(self):
        return self.find_element(bj_dy).text

    def table_invoicesid(self):
        return self.find_element(get_table_bh).text

    def insert_shuliang(self,value):
        self.send_keys(insert_quantity,value)

    def insert_shuliang1(self,value):
        self.send_keys(insert_quantity1,value)


    def get_danjuid(self):
        attribute = self.find_element(get_bh).get_attribute("value")
        return attribute

    def expected_eval(self,expected):
        return self.find_element(eval(expected)).get_attribute("value")


    #新增断言读取yml文件内容
    def insert_expcted(self):
        return self.find_element(get_table_bh).text


    def amount_exists(self):
        return self.is_exists(quantity_tips)


    #编辑按钮
    def copy(self):
        self.click(fz_btn)

    #删除按钮
    def delete(self):
        self.click(sc_btn)

    #批量操作按钮
    def bulk_action(self):
        self.click(plcz_btn)

    #批量操作，删除
    def bulk_delete(self):
        self.click(pl_delete)

    #批量操作，审核
    def bulk_audit(self):
        self.click(pl_audit)

    #批量操作，反审核
    def bulk_anti_audit(self):
        self.click(pl_anti_audit)

    #选择表格数据
    def table_data(self):
        self.click(table_check)
        self.click(table_check1)

    def cancel(self):
        self.click(cancel)



